//
//  FBBaseViewController.m
//  Fireball
//
//  Created by 俞渊华 on 2017/12/2.
//  Copyright © 2017年 俞渊华. All rights reserved.
//

#import "FBBaseViewController.h"

@interface FBBaseViewController ()
@end

@implementation FBBaseViewController

- (BOOL)shouldAutorotate {
    return NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.xm_backgroundColor = DGColor;
    self.view.backgroundColor = [UIColor whiteColor];
}
-(UIBarButtonItem *)rt_customBackItemWithTarget:(id)target action:(SEL)action{
    
    UIImage *image = [UIImage imageNamed:@"Back"];
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 30, 44);
    backButton.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [backButton setImage:image forState:UIControlStateNormal];
    [backButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc]initWithCustomView:backButton];
}

-(NSString*)eightHour:(NSDate* )theDate
{
    //时区问题多8小时问题
    NSDateFormatter *isoFormat1 = [[NSDateFormatter alloc] init];
    [isoFormat1 setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];

    NSString *timeString = @"Sun Sep 13 11:43:04 +0800 2015";

    NSTimeZone *sourceTimeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];

    NSDateFormatter *format = [[NSDateFormatter alloc] init];

    format.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSS";

    format.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

    format.timeZone = sourceTimeZone;

    NSDate *date = [format dateFromString:[isoFormat1 stringFromDate:theDate]];

    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    NSInteger interval = [zone secondsFromGMTForDate:date];
    NSDate *localDate = [date dateByAddingTimeInterval:-interval];//减掉8小时，代码不得不这么写了

    NSLog (@"date: %@", localDate );


    //原来时间代码
    NSDateFormatter *aisoFormat = [[NSDateFormatter alloc] init];
    [aisoFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS"];
    return [aisoFormat stringFromDate:localDate];
}
//利用替换先把重复元素替换掉,再根据length长度做判断
- (NSInteger )getDuplicateSubStrCountInCompleteStr:(NSString *)completeStr withSubStr:(NSString *)subStr
{
    NSInteger subStrCount = [completeStr length] - [[completeStr stringByReplacingOccurrencesOfString:subStr withString:@""] length];
    return subStrCount / [subStr length];
}
//去掉最后一个
-(NSString*) removeLastOneChar:(NSString*)origin
{
    NSString* cutted;
    if([origin length] > 0){
        cutted = [origin substringToIndex:([origin length]-1)];// 去掉最后一个","
    }else{
        cutted = origin;
    }
    return cutted;
}
@end
